#pragma once

#ifndef __EXCUTOR_H__
#define __EXCUTOR_H__

#include "IActor.h"

#include <disruptorplus/multi_threaded_claim_strategy.hpp>
//#include <disruptorplus/single_threaded_claim_strategy.hpp>
#include <disruptorplus/spin_wait_strategy.hpp>
#include <disruptorplus/ring_buffer.hpp>

namespace NTrader
{

class Excutor
{
public:
	typedef std::shared_ptr<IActor> Actor_t;

	enum ExcutorStatus
	{
		WAITING = 0,
		EXECUTING = 1,
		EXITED = 2,
	};

	Excutor();
	~Excutor();

	void Start();
	void Stop();

	void Post(Actor_t a);

protected:
	void Excute();
	
private:
	std::vector<std::thread*> __excutor;

	std::atomic<bool> __started;

	typedef disruptorplus::spin_wait_strategy WS;
	typedef disruptorplus::multi_threaded_claim_strategy<WS> CS;

	WS __waitStrategy;
	CS __claimStrategy;
	disruptorplus::sequence_barrier<WS> __consumed;
	disruptorplus::ring_buffer<Actor_t> __buffer;

	std::atomic<disruptorplus::sequence_t> __nextToRead;

	std::atomic<int> __status;
};

}
#endif

